package com.chuanyang.driverh.utils;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;

public class PermissoinUtil {

    /**
     * 在Android/data/包名/cache目下下生成一个图片文件
     * 疑问:这个目录下的文件的保存时间? 360等工具能清楚掉应用的这部分内容吗?
     */
    public static boolean checkAndRequestPermissions(Activity activityContext, String[] permission) {

        try {
            boolean result=true;
            for (int i = 0; i < permission.length; i++) {
                if (ActivityCompat.checkSelfPermission(activityContext, permission[i]) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(activityContext, new String[]{permission[i]}, i);
                    result=false;
                }
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }


    public static boolean checkAndRequestPermission(Activity activityContext, String permission, String info) throws Exception {
        try {

            if (ActivityCompat.checkSelfPermission(activityContext, permission) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(activityContext, new String[]{permission}, 100);
                PrintUtil.toast(activityContext,info);
                return false;
            } else {
                return true;
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;

    }


}
